import Vue from 'vue'
import axios from 'axios'
import {url,sginurle} from "./config"
Vue.prototype.$http=axios
//注册方法
let UserRegister=(username,password,code)=>{
     return axios.post(url+"user/public/register",{
         username:username,
         password:password,
         verification_code:code
     })
}
//获取短信验证码
let VerificationCode = (username)=>{
    return axios.post(url+"user/verification_code/send",{
        username:username
    })
}
//登录
let login = (username,password)=>{
    return axios.post(url+'user/public/login',{
        username:username,
        password:password,
        device_type:'web'
    })
}
//忘记登录密码
let PasswordReset=(username,password,code)=>{
    return axios.post(url+'user/public/passwordReset',{
        username:username,
        password:password,
        verification_code:code
    })
}
//修改登录密码
let ChangePassword = (password,password1,password2,token) =>{
    return axios.post(url+'user/profile/changePassword',
        {
                old_password:password,
                password:password1,
                confirm_password:password2
        },
        {
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':'1.1.0'
            },
           // withCredentials:true
        }
        )
}
//用户退出
let LogOut=()=>{
    return axios.post(url+'user/public/logout',{
        headers:{
            'XX-Device-Type':'web',
            'XX-Token':localStorage.getItem('token'),
            'XX-Api-Version':'1.1.0'
        }
    })
}
//用户余额记录
let Logs = (page)=>{
    return axios.get(url+'user/balance/logs',
        {
            params:{
                page:page
            },
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':'1.1.0'
            }
        }
    )
}
//获取版本号
let UserVersions=()=>{
    return axios.get('http://api.yyw66.cn/plugin/versions/Index/index')
}
//用户积分记录
let UserLogs = (page)=>{
    return axios.get(url+'user/score/logs',
        {
            params:{
                page:page
            },
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':'1.1.0'
            }
        }
    )
}
//用户信息
let UserInfo = (versions)=>{
    return axios.get(url+'user/profile/userInfo',
        {
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':versions
            }
        }
    )
}
//余额转账
let BalanceTransfer=(userid,amount,remark,token)=>{
    return axios.post(url+'user/balance/transfer',
        {
            to_user_id:userid,
            amount:amount,
            remark:remark
        },
        {
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':'1.1.0'
            }
        }
    )
}
//添加收货地址
let UserAddress = (name,tel,province,county,city,address,postalcode,code,area_code)=>{
        return axios.post(url+'user/address/add',
            {
                name:name,
                phone:tel,
                province:province,
                city:city,
                district:county,
                address:address,
                code:postalcode,
                type:code,
                area_code:area_code
            },
            {
                headers:{
                    'XX-Device-Type':'web',
                    'XX-Token':localStorage.getItem('token'),
                    'XX-Api-Version':'1.1.0'
                }
            }
            )
}
//收货地址列表
let UserAddressList =()=>{
    return axios.post(url+'user/address/index',
        {},
        {
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':'1.1.0'
            }
        }
        )
}
//支付密码设置
let PaySetting = (user_id,password)=>{
    return axios.post(url+'user/pay/Setting',
        {
            user_id:user_id,
            payment_password:password
        }
        )
}

//获取修改收货地址ID内容
let Edit = (id)=>{
    console.log(id)
    return axios.get(url+'user/address/edit',
        {
            params:{
                id:id
            },
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':'1.1.0'
            },
        }
        )
}
//收货人修改地址提交
let UserAddressEdit = (id,name,tel,province,county,city,address,postalcode,code,area_code)=>{
    return axios.post(url+'user/Address/editpost',
        {
            id:id,
            name:name,
            phone:tel,
            province:province,
            city:city,
            district:county,
            address:address,
            code:postalcode,
            type:code,
            area_code:area_code
        },
        {
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':'1.1.0'
            }
        }
      )
}
//立即签到
let UserSign = ()=>{
    return axios.post(sginurle+'sign/Index/add',
        {},
        {
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':'1.1.0'
            }
        }
        )
}
//领取红包接口
let Receive =()=>{
    return axios.post(sginurle+'sign/Index/receive',
        {},
        {
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':'1.1.0'
            }
        }
        )
}
//签到查询
let SignQuery = ()=>{
    return axios.post(sginurle+'sign/Index/index',
        {},
        {
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':'1.1.0'
            }
        }
    )
}
//邀请注册
let UserInvitation = (uid,sex,mobile,name,password,paypassword)=>{
    return axios.post(url+"/user/Invitation",
        {
            inviter_id:uid,
            sex:sex,
            mobile:mobile,
            user_nickname:name,
            user_pass:password,
            payment_password:paypassword,
        }
        )
}
//商品分类
let Categories =()=>{
    return axios.get(url+'mall/Categories'
        )
}
//商品详情
let Items = (uid)=>{
    return axios.get(url+'mall/Items/'+uid)
}
//商品小分类
let allSubCategories = (uid)=>{
    return axios.get(url+'mall/categories/allSubCategories',
        {
            params: {
                id:uid
            }
        }
        )
}
//获取商品小类列表
let MallItems = (id)=>{
    return axios.get(url+'mall/items',
        {
            params: {
                category_id: id
            }
        }
        )
}
//修改用户资料提交
let PostUserInfo = (username,avatar,sex) =>{
    return axios.post(url+'/user/profile/userInfo',
        {
            user_nickname:username,
            avatar:avatar,
            sex:sex
        },
        {
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':'1.1.0'
            }
        }
        )
}
//我的奖金
let MeBonus = (pages)=>{
    return axios.get(url+'user/bonus',
        {
            params: {
                page: pages
            },
            //977a00298a378d49e86485fd009eae66ac5b55f2adfd110dcdeb41864bd33243
            headers:{
                'XX-Device-Type':'web',
                'XX-Token':localStorage.getItem('token'),
                'XX-Api-Version':'1.1.0'
            }
        }
        )
}
//我的邀请用户
let InvitationUser = (id,page)=>{
    return axios.get(url+'user/invitation',
        {
            params: {
                inviter_id: id,
                page:page
            },
        }
        )
}
//广告
let GuangGao = ()=>{
    return axios.get('http://api.yyw66.cn/api/home/theme/more?theme=yongle_app_ad&file=portal/index')
}


export {UserRegister,VerificationCode,UserAddress,UserAddressList,PaySetting,
    Edit,UserAddressEdit,UserSign,Receive,SignQuery,UserInvitation,Items,Categories,
    allSubCategories,MallItems,PostUserInfo,MeBonus,InvitationUser,GuangGao,UserVersions,
    login,PasswordReset,ChangePassword,LogOut,Logs,BalanceTransfer,UserLogs,UserInfo}

